package com.teama4.shop.utils;

import org.springframework.web.multipart.MultipartFile;

import java.io.*;

public class FileUtil {

    public static boolean dictionary_add(MultipartFile multipartFile, String filepath, String filename) throws IOException {
        FtpUtils ftp =new FtpUtils();
        File file = File.createTempFile("tmp", null);
        multipartFile.transferTo(file);
        InputStream inputStream = new FileInputStream(file);
        ftp.uploadFile(filepath, filename, inputStream);
        return true;

    }
    public static String delFile(String filepathAndName) {
        File file = new File(filepathAndName);
        // 如果文件路径所对应的文件存在，并且是一个文件，则直接删除
        if (file.exists() && file.isFile()) {
            if (file.delete()) {
                return "ok";
            } else {
                return "fail";
            }
        } else {
            return "unExit";
        }

    }

}
